package com.gugu.procedure.util;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.teaopenapi.models.Config;

public class SmsUtil {

    /**
     * 使用AK&SK初始化账号Client
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    private static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }


    public static void senSmsCode(String mobile, String code) {
        try {
            com.aliyun.dysmsapi20170525.Client client = SmsUtil.createClient("LTAI5tBsArbBWb8dp8hLiUxZ", "mtbse1t7SLLhwV4kveAmUkjoioJtFI");
            SendSmsRequest sendSmsRequest = new SendSmsRequest();
            // 复制代码运行请自行打印 API 的返回值
            sendSmsRequest.setPhoneNumbers(mobile)
                    .setSignName("北京念念分享科技")
                    .setTemplateCode("SMS_228890122")
                    .setTemplateParam("{\"code\":\"" + code + "\"}");
            client.sendSms(sendSmsRequest);
        } catch (Exception e) {

        }

    }


    public static void main(String[] args_) {
        senSmsCode("15807004561", "123456");

    }
}
